﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 数据访问类:ChkInfoStdSuper
    /// </summary>
    public partial class ChkInfoStdSuper
    {
        public ChkInfoStdSuper()
        { }
        #region  BasicMethod

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.ChkInfoStdSuper GetModel(decimal FYear, string FDeptNo, string FEntityNo, string FInfoClsNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FYear,FBaseScore,FDeptNo,FEntityNo,FInfoClsNo,FBaseScore1,FBaseScore2,FBaseScore3,FBaseScore4 from t_chkInfoStdSuper ");
            strSql.Append(" where FYear=@FYear and FDeptNo=@FDeptNo and FEntityNo=@FEntityNo and FInfoClsNo=@FInfoClsNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInfoClsNo", SqlDbType.NVarChar,20)			};
            parameters[0].Value = FYear;
            parameters[1].Value = FDeptNo;
            parameters[2].Value = FEntityNo;
            parameters[3].Value = FInfoClsNo;

            ElingOA6_Admin_DSJCJ.Model.ChkInfoStdSuper model = new ElingOA6_Admin_DSJCJ.Model.ChkInfoStdSuper();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.ChkInfoStdSuper DataRowToModel(DataRow row)
        {
            ElingOA6_Admin_DSJCJ.Model.ChkInfoStdSuper model = new ElingOA6_Admin_DSJCJ.Model.ChkInfoStdSuper();
            if (row != null)
            {
                if (row["FYear"] != null && row["FYear"].ToString() != "")
                {
                    model.FYear = decimal.Parse(row["FYear"].ToString());
                }
                if (row["FBaseScore"] != null && row["FBaseScore"].ToString() != "")
                {
                    model.FBaseScore = decimal.Parse(row["FBaseScore"].ToString());
                }
                if (row["FDeptNo"] != null)
                {
                    model.FDeptNo = row["FDeptNo"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FInfoClsNo"] != null)
                {
                    model.FInfoClsNo = row["FInfoClsNo"].ToString();
                }
                if (row["FBaseScore1"] != null && row["FBaseScore1"].ToString() != "")
                {
                    model.FBaseScore1 = decimal.Parse(row["FBaseScore1"].ToString());
                }
                if (row["FBaseScore2"] != null && row["FBaseScore2"].ToString() != "")
                {
                    model.FBaseScore2 = decimal.Parse(row["FBaseScore2"].ToString());
                }
                if (row["FBaseScore3"] != null && row["FBaseScore3"].ToString() != "")
                {
                    model.FBaseScore3 = decimal.Parse(row["FBaseScore3"].ToString());
                }
                if (row["FBaseScore4"] != null && row["FBaseScore4"].ToString() != "")
                {
                    model.FBaseScore4 = decimal.Parse(row["FBaseScore4"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FYear,FBaseScore,FDeptNo,FEntityNo,FInfoClsNo,FBaseScore1,FBaseScore2,FBaseScore3,FBaseScore4 ");
            strSql.Append(" FROM t_chkInfoStdSuper ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "t_chkInfoStdSuper";
            parameters[1].Value = "FInfoClsNo";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  自己增加的
        /// <summary>
        /// 获取上级积分定义
        /// <creator>sunlj</creator>
        /// <date>2013-10-24</date>
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="decYear"></param>
        /// <returns></returns>
        public DataSet GetListByYear2(string strEntityNo, decimal decYear)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FBaseScore,FDeptNo,FInfoClsNo,FBaseScore1,FBaseScore2,FBaseScore3,FBaseScore4 ");
            strSql.Append(" FROM t_chkInfoStdSuper where FYear=@FYear and FEntityNo=@FEntityNo");
            strSql.Append(" and (FDeptNo in(select FDeptNo from t_chkInfoStdLocal group by FDeptNo having sum(FBaseScore)>0)");
            strSql.Append(" or FDeptNo in(select FDeptNo from t_chkInfoStdSuper group by FDeptNo having sum(FBaseScore)>0))");
            SqlParameter[] parameters = {
					new SqlParameter("@FYear", SqlDbType.Decimal),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = decYear;
            parameters[1].Value = strEntityNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        #endregion  自己增加的

    }
}

